<template>
  <div class="track_the_playback">
    <div class="around">
      <!-- 选择车辆类型 -->
      <i class="el-icon-speed" title="车辆类型">车辆类型</i>
      <el-select v-model="carTypeValue" placeholder="请选择车辆类型"  @change="screenCarList">
      <el-option
        v-for="(item,index) in selectCarType"
        :value="item.label"
        :label="item.value"
        :key="index"
      ></el-option>
      </el-select>
      <!-- 选择车辆 -->
      <i class="el-icon-speed" title="车辆名称">车辆名称</i>
      <el-select v-model="VID" placeholder="请选择车辆" ref='workcarname' filterable clearable>
      <el-option
        v-for="(item,index) in workCarSelectTypeList"
        :label="item.LICENSE_PLATE"
        :value="item.VID"
        :key="index"
      ></el-option>
      </el-select>
      <!-- 设置时间 -->
      <i
        class="el-icon-tingzhi buttonI"
        title="设置时间段"
        @click="setTime.show = true"
        >设置时间段</i
      >
      <!-- 数据列表 -->
      <i
        class="el-icon-tingzhi buttonI"
        title="打开数据列表"
        @click="openDataList"
        >打开数据列表</i
      >
      <!-- 开始播放 -->
      <i class="el-icon-kaishi buttonI" title="开始播放" @click="start"
        >开始播放</i
      >
      <!-- 停止播放 -->
      <i class="el-icon-tingzhi buttonI" title="停止播放" @click="stop"
        >暂停播放</i
      >
      <!-- 设置时间标签显示 -->
      <i class="el-icon-speed" title="设置时间标签显示">设置时间标签显示</i>
      <el-switch
        v-model="isShowTimeTap"
        active-color="#007ACC"
        style="border: 2px solid #fff; border-radius: 12px"
      ></el-switch>
      <i style="width: 5px"></i>
      <!-- 设置速度 -->
      <i
        class="el-icon-speed buttonI"
        title="设置播放速度"
        @click="speed.show = true"
        >设置播放速度</i
      >
      <!-- 设置播放间隔步数 -->
      <i
        class="el-icon-bushu buttonI"
        title="设置播放间隔"
        @click="step.show = true"
        >设置播放间隔</i
      >
      <!-- 清除轨迹 -->
      <i class="el-icon-qingchu buttonI" title="清除轨迹" @click="clear"
        >清除轨迹</i
      >
    </div>
    <!-- 地图 -->
    <div class="container" style="padding: 0px">
      <div id="map"></div>
    </div>
    <!-- 上方显示隐藏图标操作栏,多选 -->
    <div class="map-operation">
      <ul>
        <li
          v-for="(item, index) in mapOperationsList"
          :class="{ active: item.active }"
          :key="index"
          @click="changeOperationValue(item, index)"
        >
          <i :class="item.icon"></i>
          {{ item.name }}
        </li>
      </ul>
    </div>
    <!-- 播放拖动条 -->
    <div class="around">
      <el-slider
        v-model="setSlider.value"
        :step="setSlider.step"
        :max="setSlider.max"
        :format-tooltip="formatTooltipSlider"
        @input="inputSlider"
      ></el-slider>
    </div>
    <!-- 数据列表 -->
    <el-dialog
      title="点位数据列表"
      :visible.sync="dataListDialog"
      width="49%"
      class="dialogchild"
    >
      <el-form class="dialogform">
        <el-table highlight-current-row :data="dataList" style="width: 100%" fit max-height="450">
          <!-- {"Lng":"117.449241907762","Lat":"38.8629691205361","Speed":"50","Direction":"西","GpsTime":"2020/12/21 9:16:47"}, -->
          <el-table-column
            
            prop="LNG"
            label="经度"
            width="180"
            align="center"
          ></el-table-column>
          <el-table-column
            
            prop="LAT"
            label="纬度"
            width="180"
            align="center"
          ></el-table-column>
          <el-table-column
            
            prop="SPEED"
            label="速度"
            width="180"
            align="center"
          ></el-table-column>
          <el-table-column
            
            prop="DIRECTION"
            label="方向"
            width="180"
            align="center"
          ></el-table-column>
          <el-table-column
            
            prop="GPSTIME"
            label="定位时间"
            width="180"
            align="center"
            :formatter="formatterTime"
          ></el-table-column>
        </el-table>
      </el-form>
    </el-dialog>
    <!-- 设置轨迹开始时间、结束时间 -->
    <div class="set_time_box" v-if="setTime.show">
      <h2>
        <span>设置时间段</span>
        <i class="iconfont icon-guanbi" @click="setTime.show = false"></i>
      </h2>
      <div class="block"></div>
      <div class="settingWindow">
        <div>
          <span>开始日期：</span>
          <el-date-picker
            v-model="setTime.startTime"
            type="datetime"
            placeholder="选择开始日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          ></el-date-picker>
        </div>
        <div>
          <span>结束日期：</span>
          <el-date-picker
            v-model="setTime.endTime"
            type="datetime"
            placeholder="选择结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          ></el-date-picker>
          <!-- <el-date-picker v-model="setTime.endTime" placeholder="选择结束日期" value-format="yyyy-MM-dd"></el-date-picker> -->
        </div>
        <div>
          <el-button type="primary" @click="getDataList">确 定</el-button>
        </div>
      </div>
    </div>
    <!-- 设置播放速度 -->
    <div class="speed" v-if="speed.show">
      <h2>
        <span>设置播放速度</span>
        <i class="iconfont icon-guanbi" @click="speed.show = false"></i>
      </h2>
      <el-slider
        v-model="speed.value"
        :step="0.05"
        :max="1"
        :min="0.05"
        :format-tooltip="formatSpeed"
      ></el-slider>
      <el-button type="primary" @click="speed.show = false">确 定</el-button>
    </div>
    <!-- 设置播放间隔 -->
    <div class="speed" v-if="step.show">
      <h2>
        <span>设置播放间隔</span>
        <i class="iconfont icon-guanbi" @click="step.show = false"></i>
      </h2>
      <el-slider v-model="step.value" :step="1" :max="20" :min="1"></el-slider>
      <el-button type="primary" @click="step.show = false">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { formatDate } from '@/common/js/date.js'

import MapStr from '@/main.js'
import DirectionImg from '@/assets/img/playback/direction.png'
import ImageStart from '@/assets/img/playback/begin3.png'
import ImageEnd from '@/assets/img/playback/end3.png'
//垃圾设施
import imgMarkerCLC from '@/assets/img/marker/markerImageCLC.png'
import imgMarkerNCD from '@/assets/img/marker/markerImageLarge.png'
import imgMarkerCY from '@/assets/img/marker/markerImageSmall.png'
import imgMarkerXQCY from '@/assets/img/marker/markerImageVillage.png'
import imgMarkerZZZ from '@/assets/img/marker/markerImageZZZ.png'
import { newMap } from '@/common/js/map.js'
export default {
  data () {
    return {
      setSlider: {
        max: 100,
        value: 0,
        step: 1
      },
      map: null,
      mapZoom: 20,
      markerWithSlider: null,
      dataListDialog: false,
      dataList: [],
      dataCurrentIndex: 0,
      isShowTimeTap: true,
      ary: [],
      VID: 0,
      setTime: {
        show: true,
        // startTime: new Date(new Date() - 3600 * 1000 * 24),
        // endTime: new Date()
        startTime: formatDate(new Date(new Date() - 3600 * 1000 * 24), 'yyyy-MM-dd hh:mm:ss'),
        endTime: formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss'),
      },
      timeId: null,
      // 速度
      speed: {
        show: false,
        value: 0.05
      },
      // 步数
      step: {
        show: false,
        value: 1
      },
      mapOperationsList: [{
        name: '中转站',
        icon: 'el-icon-knife-fork',
        active: false
      }, {
        name: '处理厂',
        icon: 'el-icon-tableware',
        active: false
      }, {
        name: '农村垃圾点',
        icon: 'el-icon-refrigerator',
        active: false
      }, {
        name: '小区垃圾点',
        icon: 'el-icon-refrigerator',
        active: false
      }, {
        name: '餐饮单位',
        icon: 'el-icon-refrigerator',
        active: false
      }],
      MapV: {
        dataSetDic_Vehicle: {},
        dataSetDic_Worker: {},
        dataSetDic_Rubbish: {},
        // arrayVIcon_Vehicle: [],
        // arrayVText_Vehicle: [],
        // arrayVIcon_Worker: [],
        // arrayVText_Worker: [],
        // arrayVIcon_Rubbish: [],
        // arrayVText_Rubbish: [],
        VIcon_Installations: {},
        VText_Installations: {}
      },
      MapOverlay: {
        warningMarker: '',
        arrayCLCMapOverlay: [],
        arrayZZZMapOverlay: [],
        arrayNCDMapOverlay: [],
        arrayCYMapOverlay: [],
        arrayXQCYMapOverlay: [],

        arrayCarMapOverlay: [],
        arrayRubbishMapOverlay: [],
        arrayWorkerMapOverlay: [],
        arrayToiletCarMapOverlay: [],
        arrayToiletWorkerMapOverlay: [],
        arrayToiletMapOverlay: []
      },
      Data: {
        arrayCLCPolygonData: [],

        arrayCLCMarkerData: [],
        arrayZZZMarkerData: [],
        arrayNCDMarkerData: [],
        arrayXQCYMarkerData: [],
        arrayCYMarkerData: [],

        arrayCarData: [],
        arrayRubbishData: [],
        arrayWorkerData: [],
        arrayToiletCarData: [],
        arrayToiletWorkerData: [],
        arrayToiletData: [],

        arrayForType_Veicle: [],
        arrayForType_Rubbish: [],
        arrayForType_Worker: []
      },
      workCarSelectTypeList: [],
      carTypeValue: '全部',
      selectCarType: [{
        value: '全部',
        label: '全部'
      }, {
        value: '餐厨车',
        label: '餐厨车'
      }, {
        value: '勾臂车',
        label: '勾臂车'
      }, {
        value: '挤压车',
        label: '挤压车'
      }, {
        value: '吸粪车',
        label: '吸粪车'
      }, {
        value: '小型垃圾车',
        label: '小型垃圾车'
      }, {
        value: '有害垃圾车',
        label: '有害垃圾车'
      }, {
        value: '自卸车',
        label: '自卸车'
      }, {
          value: '小型冲洗车',
          label: '小型冲洗车'
        }],
    }
  },
  created () {
    var intVID = this.$route.query.VID
    this.VID = intVID.toString()  
    this.carTypeValue = this.$route.query.CARTYPE
  },
  methods: {
    // 显示地图
    mapShow () {
      // 百度地图API功能
      this.map = newMap();
      this.map.centerAndZoom(new BMap.Point(MapStr.DefaultPointX, MapStr.DefaultPointY), this.mapZoom)// 初始化地图,设置中心点坐标和地图级别
  
      var myIcon = new BMap.Icon(DirectionImg, new BMap.Size(32, 32), { anchor: new BMap.Size(20, 20) })
      this.markerWithSlider = new BMap.Marker(new BMap.Point(0, 0), { icon: myIcon })
      this.markerWithSlider.disableMassClear()
      this.map.addOverlay(this.markerWithSlider)
    },
    async getCarList () {
      // let date = new Date(this.$refs.historytime.value);
      // let str=formatDate(date,'yyyy-MM-dd');
      // var url = 'Vehicle/GetCarInfo?workdate=' + this.setTime.startTime + '&client_no=' + localStorage.getItem('CLIENT_NO') // zxdata
      var url = 'RubbishVehicle/GetVehicleCarListSelect?ClientNo=' + localStorage.getItem('CLIENT_NO')
      let { data } = await this.$Http.get(url)
      this.workCarList = data;
      this.screenCarList()
    },
    screenCarList () {
      console.log(this.carTypeValue)
      if (this.carTypeValue !== '全部') this.workCarSelectTypeList = this.workCarList.filter(item => item.CAR_TYPE === this.carTypeValue)
    },
    // 选定时间段,获取数据列表
    async getDataList () { // 16232
      if (this.setTime.startTime === '' || this.setTime.endTime === '') {
        this.$message({
          message: '请选择日期',
          type: 'warning'
        })
        return false
      }
      const params = {
        VID: this.VID,
        StartDate: this.setTime.startTime,
        EndDate: this.setTime.endTime
      }
      console.log(params)
      // 设置加载效果
      const loading = this.$loading({
        lock: true,
        text: '数据加载中...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.5)'
      })
      const { data } = await this.$Http.get('RubbishVehicle/GetVehicleHistoryInfo', { params })
      loading.close()
      if (data.length != 0) {
        this.dataList = data
        this.setTime.show = false
        this.setSlider.max = this.dataList.length
        this.drawPicture()
      } else {
        this.$message.error('未获取到轨迹');
      }
    },
    // 轨迹回放逐步播放点
    async playTrack () {
      const data = this.dataList
      // 以第一个坐标点为地图中心点
      // this.map.centerAndZoom(new BMap.Point(data[0].LNG, data[0].LAT), 20)
      const _this = this

      // 定时画线
      this.timeId = setInterval(() => {
        // 清除定时器，停止画线
        if (this.dataCurrentIndex === data.length - 1) {
          this.stop()
          this.dataCurrentIndex = 0
          return true
        }
        // 上一个点
        this.dataCurrentIndex = this.dataCurrentIndex + this.step.value
        const prevPoint = this.dataCurrentIndex - this.step.value
        add(data[prevPoint])

        // 下一个点
        this.createPoint(data[prevPoint].LNG, data[prevPoint].LAT, data[this.dataCurrentIndex].LNG, data[this.dataCurrentIndex].LAT, data[prevPoint].GPSTIME)
      }, 1000 * this.speed.value)
      // })
      // 画线
      function add (point) {
        _this.ary.push(new BMap.Point(point.LNG, point.LAT))
        const polyline = new BMap.Polyline(_this.ary, { strokeColor: 'red', strokeWeight: 3, strokeOpacity: 1 })
        _this.map.addOverlay(polyline)
      }
    },
    // 创建标记点
    createPoint (lng1, lat1, lng2, lat2, datePoint) {
      // 获取两个标记点的角度
      const k = this.getAngle(lng1, lat1, lng2, lat2)
      // 创建标记点
      const pt = new BMap.Point(lng1, lat1)
      // 标记点图片
      const myIcon = new BMap.Icon(DirectionImg, new BMap.Size(20, 26))
      // 添加图片
      const marker = new BMap.Marker(pt, { icon: myIcon })
      // 设置标记点方向
      marker.setRotation(k)
      // 将标注添加到地图中
      this.map.addOverlay(marker)
      if (this.isShowTimeTap) {
        var label = new BMap.Label(datePoint.replace('T', ' '), { offset: new BMap.Size(-10, 50) })
        marker.setLabel(label)
      }
      // 如果点位在当前地图显示范围外，则将该点设置为地图中心
      if (!this.map.getBounds().containsPoint(pt)) {
        this.map.centerAndZoom(pt, this.mapZoom)
      }
    },
    // 获取两个点的角度
    getAngle (lng1, lat1, lng2, lat2) {
      const a = (90 - lat2) * Math.PI / 180
      const b = (90 - lat1) * Math.PI / 180
      const AOC_BOC = (lng2 - lng1) * Math.PI / 180
      const cosc = Math.cos(a) * Math.cos(b) + Math.sin(a) * Math.sin(b) * Math.cos(AOC_BOC)
      const sinc = Math.sqrt(1 - cosc * cosc)
      const sinA = Math.sin(a) * Math.sin(AOC_BOC) / sinc
      const A = Math.asin(sinA) * 180 / Math.PI
      let res = 0
      if (lng2 > lng1 && lat2 > lat1) res = A
      else if (lng2 > lng1 && lat2 < lat1) res = 180 - A
      else if (lng2 < lng1 && lat2 < lat1) res = 180 - A
      else if (lng2 < lng1 && lat2 > lat1) res = 360 + A
      else if (lng2 > lng1 && lat2 === lat1) res = 90
      else if (lng2 < lng1 && lat2 === lat1) res = 270
      else if (lng2 === lng1 && lat2 > lat1) res = 0
      else if (lng2 === lng1 && lat2 < lat1) res = 180
      return res
    },
    // 打开数据列表
    openDataList () {
      this.dataListDialog = true
    },
    //画出整个轨迹
    drawPicture () {
      var pointArr = []
      // for (var i = 0; i < this.dataList.length; i++) {
      for (const item of this.dataList) {
        // pointArr.push(new BMap.Point(item.LNG, item.LAT))
        item.GPSTIME = item.GPSTIME.replace('T', ' ')
        pointArr.push(new BMap.Point(item.LNG, item.LAT))
      }
      // console.log('位置数组' + pointArr)
      var polyline = new BMap.Polyline(pointArr, {
        strokeColor: 'blue',
        strokeWeight: 5,
        strokeOpacity: 2
      })
      this.map.addOverlay(polyline)

      var markerStart = new BMap.Marker(new BMap.Point(this.dataList[0].LNG, this.dataList[0].LAT), { icon: new BMap.Icon(ImageStart, new BMap.Size(40, 34), { anchor: new BMap.Size(20, 34) }) })
      this.map.addOverlay(markerStart)
      var markerEnd = new BMap.Marker(new BMap.Point(this.dataList[(this.dataList.length - 1)].LNG, this.dataList[(this.dataList.length - 1)].LAT), { icon: new BMap.Icon(ImageEnd, new BMap.Size(40, 34), { anchor: new BMap.Size(20, 34) }) })
      this.map.addOverlay(markerEnd)

      // this.map.centerAndZoom(markerStart.getPosition(), this.mapZoom)
      // this.map.centerAndZoom(polyline.getBounds().getCenter(), 15);
      this.map.setViewport(pointArr);
    },
    inputSlider (val) {
      // console.log(this.setSlider.value)
      // 设置标记点坐标位置
      var pointChangeSlider = new BMap.Point(this.dataList[val].LNG, this.dataList[val].LAT)
      this.markerWithSlider.setPosition(pointChangeSlider)
      // 获取两个标记点的角度
      var k = 0
      if (val > 0) {
        k = this.getAngle(this.dataList[(val - 1)].LNG, this.dataList[(val - 1)].LAT, this.dataList[val].LNG, this.dataList[val].LAT)
      }
      // 设置标记点方向
      this.markerWithSlider.setRotation(k)
      // 如果点位在当前地图显示范围外，则将该点设置为地图中心
      if (!this.map.getBounds().containsPoint(pointChangeSlider)) {
        this.map.centerAndZoom(pointChangeSlider, this.mapZoom)
      }
    },
    // 开始播放
    start () {
      this.dataListDialog = false
      // if (this.dataCurrentIndex === 0) {
      //   this.clear()
      // }
      if (this.timeId == null) {
        this.playTrack()
      }

    },
    // 停止播放
    stop () {
      clearTimeout(this.timeId)
      this.timeId = null
    },
    // 清除轨迹
    clear () {
      this.stop()
      this.ary = []
      this.dataCurrentIndex = 0
      this.markerWithSlider.setPosition(new BMap.Point(0, 0))
      this.map.clearOverlays()
    },
    // 格式化播放间隔
    formatSpeed (val) {
      return val + ' 秒播放一步'
    },
    formatTooltipSlider (val) {
      if (val > 0) {
        return this.dataList[val - 1].GPSTIME
      }
    },
    // 获取处理厂
    async getPlacePointCLCApi () {
      var url = 'RubbishVehicle/getPlaceCLC?CLIENTNO=' + localStorage.getItem('CLIENT_NO')
      let { data } = await this.$Http.get(url)
      this.Data.arrayCLCMarkerData = data
    },
    // 获取中转站
    async getPlacePointZZZApi () {
      var url = 'RubbishVehicle/getPlaceZZZ?CLIENTNO=' + localStorage.getItem('CLIENT_NO')
      let { data } = await this.$Http.get(url)
      this.Data.arrayZZZMarkerData = data
    },
    // 获取农村点
    async getPlacePointNCDApi () {
      var url = 'RubbishVehicle/getPlaceNCD?CLIENTNO=' + localStorage.getItem('CLIENT_NO')
      let { data } = await this.$Http.get(url)
      this.Data.arrayNCDMarkerData = data
    },
    // 获取餐饮单位
    async getPlacePointCYApi () {
      var url = 'RubbishVehicle/mapPlacePointCY?CLIENTNO=' + localStorage.getItem('CLIENT_NO')
      let { data } = await this.$Http.get(url)
      this.Data.arrayCYMarkerData = data
    },
    // 获取小区垃圾点
    async getPlacePointXQCYApi () {
      var url = 'RubbishVehicle/getPlaceXQCY?CLIENTNO=' + localStorage.getItem('CLIENT_NO')
      let { data } = await this.$Http.get(url)
      this.Data.arrayXQCYMarkerData = data
    },
    async handleCheckZZZ () {
      let key = 'ZZZ'
      var vIcon = this.MapV.VIcon_Installations[key]
      var vText = this.MapV.VText_Installations[key]
      if (this.mapOperationsList[0].active) {
        if (vIcon) {
          vIcon.show()
          vText.show()
        } else {
          this.drawMapVUnmove(this.Data.arrayZZZMarkerData, imgMarkerZZZ, key)

        }
      } else {
        vIcon.hide()
        vText.hide()
      }
    },
async handleCheckCLC () {
      let key = 'CLC'
      var vIcon = this.MapV.VIcon_Installations[key]
      var vText = this.MapV.VText_Installations[key]
      if (this.mapOperationsList[1].active) {
        if (vIcon) {
          vIcon.show()
          vText.show()
        } else {
          this.drawMapVUnmove(this.Data.arrayCLCMarkerData, imgMarkerCLC, key)

        }
      } else {
        vIcon.hide()
        vText.hide()
      }
    },
async handleCheckNCD () {
      let key = 'NCD'
      var vIcon = this.MapV.VIcon_Installations[key]
      var vText = this.MapV.VText_Installations[key]
      if (this.mapOperationsList[2].active) {
        if (vIcon) {
          vIcon.show()
          vText.show()
        } else {
          this.drawMapVUnmove(this.Data.arrayNCDMarkerData, imgMarkerNCD, key)

        }
      } else {
        vIcon.hide()
        vText.hide()
      }
    },
async handleCheckXQCY () {
      let key = 'XQCY'
      var vIcon = this.MapV.VIcon_Installations[key]
      var vText = this.MapV.VText_Installations[key]
      if (this.mapOperationsList[3].active) {
        if (vIcon) {
          vIcon.show()
          vText.show()
        } else {
          this.drawMapVUnmove(this.Data.arrayXQCYMarkerData, imgMarkerXQCY, key)

        }
      } else {
        vIcon.hide()
        vText.hide()
      }
    },
async handleCheckCY () {
      let key = 'CY'
      var vIcon = this.MapV.VIcon_Installations[key]
      var vText = this.MapV.VText_Installations[key]
      if (this.mapOperationsList[4].active) {
        if (vIcon) {
          vIcon.show()
          vText.show()
        } else {
          this.drawMapVUnmove(this.Data.arrayCYMarkerData, imgMarkerCY, key)

        }
      } else {
        vIcon.hide()
        vText.hide()
      }
    },
    async drawMapVUnmove (arrayPoint, icon, key) {
      // if (this.mapOperationsList[1].active) {
      const _self = this;

      let img = new Image();
      img.src = icon
      img.onload = function () {
        //循环加载同一张图片的车辆数据
        let arrayImage = arrayPoint.map(v => {
          v.geometry = {
            type: 'Point',
            coordinates: [v.LONGITUDE, v.LATITUDE]
          }
          v.icon = img;
          v.text = v.NAME;
          return v;
        })

        let dataSet = new mapv.DataSet(arrayImage);

        let optionsICON = {
          draw: 'icon',
          width: 35, // 规定图像的宽度
          height: 35, // 规定图像的高度
          // offset: { // 文本便宜值
          //       x: 0,
          //       y: 20
          //     }
        }

        let optionsTEXT = {
          draw: 'text',
          size: 14,
          avoid: true, // 开启文本标注避让
          textBaseline: 'middle',
          offset: { // 文本便宜值
            x: 0,
            y: 25
          }
        }
        _self.MapV.VIcon_Installations[key] = new mapv.baiduMapLayer(_self.map, dataSet, optionsICON)
        _self.MapV.VText_Installations[key] = new mapv.baiduMapLayer(_self.map, dataSet, optionsTEXT)
      }
      // }else{
      //   mapVIcon.sh
      // }
    },
    // async handleCheckZZZ () {
    //   console.log(this.Data.arrayZZZMarkerData)
    //   if (this.mapOperationsList[0].active) {
    //     this.Data.arrayZZZMarkerData.forEach(element => {
    //       // {"ID":1,"NAME":"1984生活广场","PARENT_NO":"0000019","PARENT_NAME":null,"CLIENT_NO":"000001900","CLIENT_NAME":"塘沽","TYPE":3,"LONGITUDE":117.706085,"LATITUDE":39.02312,"UPDATE_TIME":"2020-12-23T17:14:21.78"}
    //       var point = new BMap.Point(element.LONGITUDE, element.LATITUDE)
    //       var markerImage = new BMap.Icon(imgMarkerZZZ, new BMap.Size(50, 50))
    //       var marker = new BMap.Marker(point, { icon: markerImage })
    //       var label = new BMap.Label(element.NAME, { offset: new BMap.Size(-10, 50) })
    //       marker.setLabel(label)
    //       marker.disableMassClear()
    //       this.map.addOverlay(marker)
    //       this.MapOverlay.arrayZZZMapOverlay.push(marker)
    //     })
    //   } else {
    //     for (var i = 0; i < this.MapOverlay.arrayZZZMapOverlay.length; i++) {
    //       this.MapOverlay.arrayZZZMapOverlay[i].enableMassClear()
    //       this.map.removeOverlay(this.MapOverlay.arrayZZZMapOverlay[i])
    //     }
    //     this.MapOverlay.arrayZZZMapOverlay = []
    //   }
    // },
    // async handleCheckCLC () {
    //   if (this.mapOperationsList[1].active) {
    //     this.Data.arrayCLCMarkerData.forEach(element => {
    //       // {"ID":1,"NAME":"1984生活广场","PARENT_NO":"0000019","PARENT_NAME":null,"CLIENT_NO":"000001900","CLIENT_NAME":"塘沽","TYPE":3,"LONGITUDE":117.706085,"LATITUDE":39.02312,"UPDATE_TIME":"2020-12-23T17:14:21.78"}
    //       var point = new BMap.Point(element.LONGITUDE, element.LATITUDE)
    //       var markerImage = new BMap.Icon(imgMarkerCLC, new BMap.Size(50, 50))
    //       var marker = new BMap.Marker(point, { icon: markerImage })
    //       var label = new BMap.Label(element.NAME, { offset: new BMap.Size(-10, 50) })
    //       marker.setLabel(label)
    //       marker.disableMassClear()
    //       this.map.addOverlay(marker)
    //       this.MapOverlay.arrayCLCMapOverlay.push(marker)
    //     });
    //   } else {
    //     for (var i = 0; i < this.MapOverlay.arrayCLCMapOverlay.length; i++) {
    //       this.MapOverlay.arrayCLCMapOverlay[i].enableMassClear()
    //       this.map.removeOverlay(this.MapOverlay.arrayCLCMapOverlay[i])
    //     }
    //     this.MapOverlay.arrayCLCMapOverlay = []
    //   }
    // },
    // async handleCheckNCD () {
    //   if (this.mapOperationsList[2].active) {
    //     this.Data.arrayNCDMarkerData.forEach(element => {
    //       // {"ID":1,"NAME":"1984生活广场","PARENT_NO":"0000019","PARENT_NAME":null,"CLIENT_NO":"000001900","CLIENT_NAME":"塘沽","TYPE":3,"LONGITUDE":117.706085,"LATITUDE":39.02312,"UPDATE_TIME":"2020-12-23T17:14:21.78"}
    //       var point = new BMap.Point(element.LONGITUDE, element.LATITUDE)
    //       var markerImage = new BMap.Icon(imgMarkerNCD, new BMap.Size(50, 50))
    //       var marker = new BMap.Marker(point, { icon: markerImage })
    //       var label = new BMap.Label(element.POINTNAME, { offset: new BMap.Size(-10, 50) })
    //       marker.setLabel(label)
    //       marker.disableMassClear()
    //       this.map.addOverlay(marker)
    //       this.MapOverlay.arrayNCDMapOverlay.push(marker)
    //     });
    //   } else {
    //     for (var i = 0; i < this.MapOverlay.arrayNCDMapOverlay.length; i++) {
    //       this.MapOverlay.arrayNCDMapOverlay[i].enableMassClear()
    //       this.map.removeOverlay(this.MapOverlay.arrayNCDMapOverlay[i])
    //     }
    //     this.MapOverlay.arrayNCDMapOverlay = []
    //   }
    // },
    // async handleCheckCY () {
    //   if (this.mapOperationsList[4].active) {
    //     this.Data.arrayCYMarkerData.forEach(element => {
    //       // {"ID":1,"NAME":"1984生活广场","PARENT_NO":"0000019","PARENT_NAME":null,"CLIENT_NO":"000001900","CLIENT_NAME":"塘沽","TYPE":3,"LONGITUDE":117.706085,"LATITUDE":39.02312,"UPDATE_TIME":"2020-12-23T17:14:21.78"}
    //       var point = new BMap.Point(element.LONGITUDE, element.LATITUDE)
    //       var markerImage = new BMap.Icon(imgMarkerCY, new BMap.Size(50, 50))
    //       var marker = new BMap.Marker(point, { icon: markerImage })
    //       var label = new BMap.Label(element.POINTNAME, { offset: new BMap.Size(-10, 50) })
    //       marker.setLabel(label)
    //       marker.disableMassClear()
    //       this.map.addOverlay(marker)
    //       this.MapOverlay.arrayCYMapOverlay.push(marker)
    //     });
    //   } else {
    //     for (var i = 0; i < this.MapOverlay.arrayCYMapOverlay.length; i++) {
    //       this.MapOverlay.arrayCYMapOverlay[i].enableMassClear()
    //       this.map.removeOverlay(this.MapOverlay.arrayCYMapOverlay[i])
    //     }
    //     this.MapOverlay.arrayCYMapOverlay = []
    //   }
    // },
    // //小区
    // async handleCheckXQCY () {
    //   if (this.mapOperationsList[3].active) {
    //     this.Data.arrayXQCYMarkerData.forEach(element => {
    //       // {"ID":1,"NAME":"1984生活广场","PARENT_NO":"0000019","PARENT_NAME":null,"CLIENT_NO":"000001900","CLIENT_NAME":"塘沽","TYPE":3,"LONGITUDE":117.706085,"LATITUDE":39.02312,"UPDATE_TIME":"2020-12-23T17:14:21.78"}
    //       var point = new BMap.Point(element.LONGITUDE, element.LATITUDE)
    //       var markerImage = new BMap.Icon(imgMarkerXQCY, new BMap.Size(50, 50))
    //       var marker = new BMap.Marker(point, { icon: markerImage })
    //       var label = new BMap.Label(element.POINTNAME, { offset: new BMap.Size(-10, 50) })
    //       marker.setLabel(label)
    //       marker.disableMassClear()
    //       this.map.addOverlay(marker)
    //       this.MapOverlay.arrayXQCYMapOverlay.push(marker)
    //     });
    //   } else {
    //     for (var i = 0; i < this.MapOverlay.arrayXQCYMapOverlay.length; i++) {
    //       this.MapOverlay.arrayXQCYMapOverlay[i].enableMassClear()
    //       this.map.removeOverlay(this.MapOverlay.arrayXQCYMapOverlay[i])
    //     }
    //     this.MapOverlay.arrayXQCYMapOverlay = []
    //   }
    // },
    async handleCheckCLCPolygon () {
      // if (document.getElementById('checkbox_clc').checked) {
      var pointPolygon = []
      this.Data.arrayCLCPolygonData.forEach(item => {
        var point = new BMap.Point(item.经度, item.纬度)
        pointPolygon.push(point)
      })
      var polygon = new BMap.Polygon(pointPolygon)
      polygon.disableMassClear()
      this.map.addOverlay(polygon)
      this.MapOverlay.arrayCLCMapOverlay.push(polygon)
    },
    // 改变右上方显示隐藏图标
    changeOperationValue (item, index) {

      item.active = !item.active

      switch (index) {
        case 0:
          this.handleCheckZZZ()
          break;
        case 1:
          this.handleCheckCLC()
          break;
        case 2:
          this.handleCheckNCD()
          break;
        case 3:
          this.handleCheckXQCY()
          break;
        case 4:
          this.handleCheckCY()
          break;
        default:
          break;
      }
    }
  },
  mounted () {
    // 显示地图  
    this.mapShow()
    this.getCarList()
    // this.getClcList()
    this.getPlacePointZZZApi()
    this.getPlacePointCLCApi()
    this.getPlacePointNCDApi()
    this.getPlacePointCYApi()
    this.getPlacePointXQCYApi()
    // 画线
    // setTimeout(() => {
    //   this.addLine()
    // }, 2000)
  }
}
</script>

<style scoped lang="less">
/deep/.BMap_cpyCtrl {
  display: none !important;
}
/deep/.anchorBL {
  display: none !important;
}
.buttonI {
  border: 1px solid #fff;
  padding: 0px 8px;
  border-radius: 6px;
}
.track_the_playback {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  .around {
    padding: 10px 100px;
    height: 40px;
    background-color: #007acc;
    &:first-child {
      padding-left: 10px;
      height: 60px;
      // line-height: 30px;
      i {
        color: #fff;
        font-size: 18px;
        font-weight: bold;
        //width: 30px;
        height: 30px;
        line-height: 28px;
        text-align: center;
        vertical-align: middle;
        cursor: pointer;
        margin-right: 15px;
      }
      // .el-icon-s-operation {
      //   font-size: 22px;
      // }
    }
  }
  .container {
    flex: 1;
    #map {
      height: 100%;
    }
  }
}
h2 {
  font-size: 16px;
  height: 30px;
  line-height: 30px;
  padding-left: 15px;
  border-bottom: 2px solid #ccc;
  background-color: #f1f1f1;
  i {
    float: right;
    margin-right: 10px;
  }
}
.settingWindow {
  height: calc(~'100% - 32px');
}
.data_list {
  height: 485px;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-color: #fff;
  box-shadow: 0 0 5px 3px #ccc;
  border-radius: 8px;
  overflow: hidden;
}
.set_time_box {
  width: 340px;
  height: 160px;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 4px;
  box-shadow: 0 0 5px 3px #ccc;
  background-color: #fff;
  h2 {
    border-bottom: 1px solid #ccc;
  }
  .settingWindow {
    padding-top: 10px;
    & > div {
      height: 26px;
      line-height: 26px;
      margin-bottom: 5px;
      padding-left: 20px;
      & > span {
        padding-right: 15px;
      }
      & > .el-button {
        float: right;
        padding: 0 5px;
        margin-right: 10px;
        height: 26px;
        bottom: 20px;
        right: 20px;
        position: absolute;
      }
    }
    /deep/.el-date-editor.el-input {
      width: 190px;
    }
    /deep/.el-input--prefix .el-input__inner {
      height: 26px;
      border-radius: 2px;
      padding: 0;
      padding-left: 5px;
      overflow: hidden;
      border-color: #007acc;
      padding: 0;
      padding-left: 20px;
    }
    /deep/.el-input__icon {
      line-height: 26px;
    }
    /deep/.el-input__prefix {
      left: -1px;
    }
  }
}
.person_top {
  width: 150px;
  height: 130px;
  position: absolute;
  left: 20px;
  top: 100px;
  background-color: #b2dfee;
  border: 1px solid #ccc;
  p {
    height: 30px;
    // text-align: center;
    padding-left: 5px;
    padding-left: 10px;
    color: #333;
    span:first-child {
      text-align: center;
      padding-top: 14px;
      display: inline-block;
      width: 30px;
      height: 30px;
      margin-right: 5px;
      vertical-align: middle;
      img {
        background-size: 30px 30px;
      }
    }
  }
}
.speed {
  width: 300px;
  height: 120px;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 0 5px 3px #ccc;
  background-color: #fff;
  .el-slider {
    margin: 10px 15px 0px;
    padding: 0 10px;
  }
  .el-button {
    float: right;
    margin-right: 15px;
    padding: 0 5px;
    height: 26px;
  }
  .el-switch {
    border: 2px solid #fff;
  }
}
.map-operation {
  position: absolute;
  right: 35%;
  top: 180px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #dcdfe6;
  border-radius: 5px;
  ul {
    li {
      list-style: none;
      float: left;
      color: #666;
      font-size: 14px;
      padding: 5px 12px;
      position: relative;
      cursor: pointer;
      i {
        margin-right: 3px;
        font-size: 14px;
        &:before {
          font-size: inherit;
          color: inherit;
        }
      }
      &::before {
        display: block;
        content: '';
        width: 1px;
        height: 13px;
        background: #dcdfe6;
        position: absolute;
        right: 0;
        top: 8px;
      }
      &:last-child {
        &::before {
          display: none;
        }
      }
      &.active {
        color: #007acc;
      }
    }
  }
}

</style>
